package com.mezo.athena.web.controller.common;


import com.alibaba.fastjson2.JSONObject;
import com.mezo.athena.common.core.domain.AjaxResult;
import com.mezo.athena.common.utils.qrcode.QrCodeUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/qrcode")
public class QrCodeController {

    @GetMapping("/create")
    public AjaxResult createGeneral(String concent) {
        String base64QRCode = QrCodeUtils.getBase64QRCode(concent);
        return AjaxResult.success(base64QRCode);
    }

    @PostMapping("/create")
    public AjaxResult createLogo(@RequestBody JSONObject json) {
        String base64QRCode = "";
        String concent = json.getString("concent");
        String url = json.getString("url");
        Integer height = json.getInteger("height");
        Integer width = json.getInteger("width");
        Integer logoHeight = json.getInteger("logoHeight");
        Integer logoWidth = json.getInteger("logoWidth");
        if (height != null && width != null && logoHeight != null && logoWidth != null) {
            base64QRCode = QrCodeUtils.getBase64QRCode(concent, width, height, url, logoWidth, logoHeight);
        } else {
            base64QRCode = QrCodeUtils.getBase64QRCode(concent, url);
        }
        return AjaxResult.success(base64QRCode);
    }
}

